﻿using TestCases.CompareAssert.Core.Interfaces;

namespace TestCases.CompareAssert.Core
{
    public class ComparerObject : IComparerObject
    {
        private readonly object _obj;
        private readonly IPathBuilder _pathBuilder;

        private ComparerObject(object obj, string objectName)
        {
            _obj = obj;
            _pathBuilder = new PathBuilder(objectName);
        }

        private ComparerObject(object obj, IPathBuilder pathBuilder)
        {
            _obj = obj;
            _pathBuilder = pathBuilder;
        }

        public string Path
        {
            get { return _pathBuilder.Path; }
        }

        public object Object
        {
            get { return _obj; }
        }

        public IComparerObject IndexedObject(object targetObject, params object[] indexes)
        {
            return new ComparerObject(targetObject, new PathBuilder(_pathBuilder).Indexes(indexes));
        }

        public IComparerObject MethodObject(object targetObject, string name, params object[] parameters)
        {
            return new ComparerObject(targetObject, new PathBuilder(_pathBuilder).Method(name, parameters));
        }

        public IComparerObject EntityObject(object targetObject, string name)
        {
            return new ComparerObject(targetObject, new PathBuilder(_pathBuilder).Entity(name));
        }

        public static IComparerObject RootObject(object obj, string objectName)
        {
            return new ComparerObject(obj, objectName);
        }
    }
}